#include <iostream>
#include <vector>
#include <queue>

using namespace std;

class Bonus {
public:
    int getMost(vector<vector<int> > board) {
        vector<vector<int>> dp(7, vector<int>(7, 0));

        for (int i = 1; i < 7; i++)
        {
            for (int j = 1; j < 7; j++)
            {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + board[i - 1][j - 1];
            }
        }

        return dp[6][6];
    }
};


//////////////////////////////////

//int main()
//{
//    queue<int> q;
//    q.push(1);
//    q.push(2);
//    q.push(3);
//    q.push(4);
//    q.push(5);
//    q.push(6);
//    
//    q.pop();
//    q.pop();
//    q.pop();
//    q.pop();
//
//    return 0;
//}

#include <iostream>
#include <queue>
#include <vector>
using namespace std;

struct node
{
    node(int x = 0, int y = 0)
        :_x(x)
        , _y(y)
    {}

    int _x = 0;
    int _y = 0;
    node* _left = nullptr;
    node* _right = nullptr;
    node* _down = nullptr;
    node* _up = nullptr;
};

void dfs(node* root, vector<node*> path, vector<vector<node*>>& ans)
{
    if (root == nullptr)
    {
        ans.push_back(path);
        return;
    }

    path.push_back(root);
    dfs(root->_down, path, ans);
    dfs(root->_right, path, ans);
    dfs(root->_up, path, ans);
    dfs(root->_left, path, ans);
}

int main()
{
    int n = 0, m = 0;
    cin >> n >> m;
    vector<vector<int>> broad(n, vector<int>(m));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            int tmp = 0;
            cin >> tmp;
            broad[i][j] = tmp;
        }
    }

    node* root = new node(0, 0);
    queue<node*> q;
    q.push(root);
    while (!q.empty())
    {
        node* top = q.front();
        q.pop();
        int x = top->_x;
        int y = top->_y;
        broad[x][y] = 1;

        if (x + 1 < n && y < m && broad[x + 1][y] != 1)
        {
            node* down = new node(x + 1, y);
            top->_down = down;
            q.push(down);
        }
        if (x < n && y + 1 < m && broad[x][y + 1] != 1)
        {
            node* right = new node(x, y + 1);
            top->_right = right;
            q.push(right);
        }
        if (x - 1 > 0 && y < m && broad[x - 1][y] != 1)
        {
            node* up = new node(x - 1, y);
            top->_up = up;
            q.push(up);
        }
        if (x < n && y - 1 > 0 && broad[x][y - 1] != 1)
        {
            node* left = new node(x, y - 1);
            top->_left = left;
            q.push(left);
        }
    }

    vector <vector<node*>> ans;
    vector<node*> path;
    dfs(root, path, ans);

    int minLen = n * m;
    int index = 0;
    int size = ans.size();
    for (int i = 0; i < size; i++)
    {
        if (ans[i].back()->_x == n - 1 && ans[i].back()->_y == m - 1)
        {
            if (minLen > ans[i].size())
            {
                index = i;
                minLen = ans[i].size();
            }
        }
    }

    for (auto val : ans[index])
    {
        cout << "(" << val->_x << "," << val->_y << ")" << endl;
    }
    return 0;
}
